<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="UTF-8">
<title>图书管理</title>
<jsp:include page="/WEB-INF/include/base.jsp"></jsp:include>
<script type="text/javascript">
	$(function () {
		$(".deleteA").click(function () {
			if(!confirm("确认删除吗？")){
				return false;//取消超链接的默认行为
			}
		});

		$("#btnId").click(function () {
			//获取用户输入的页码
			var pageNo = $("#pn_input").val();
			location = "BookManagerServlet?method=getBookPage&pageNo="+pageNo;
		});
	});
</script>
</head>
<body>
	
	<div id="header">
			<img class="logo_img" alt="" src="static/img/logo.gif" >
			<span class="wel_word">图书管理系统</span>
			<jsp:include page="/WEB-INF/include/manager_head.jsp"></jsp:include>
	</div>
	
	<div id="main">
		<table>
			<tr>
				<td></td>
				<td>名称</td>
				<td>价格</td>
				<td>作者</td>
				<td>销量</td>
				<td>库存</td>
				<td colspan="2">操作</td>
			</tr>

			<c:forEach items="${requestScope.list}" var="book" varStatus="status">
				<tr>
					<td>${pageScope.status.count}</td>
					<td>${pageScope.book.title}</td>
					<td>${pageScope.book.price}</td>
					<td>${pageScope.book.author}</td>
					<td>${pageScope.book.sales}</td>
					<td>${pageScope.book.stock}</td>
					<td><a href="BookManagerServlet?method=toUpdate&id=${pageScope.book.id}">修改</a></td>
					<td><a class="deleteA" href="BookManagerServlet?method=deleteBook&id=${pageScope.book.id}">删除</a></td>
				</tr>
			</c:forEach>

			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td><a href="pages/manager/book_edit.jsp">添加图书</a></td>
			</tr>	
		</table>

		<div id="page_nav" style="margin-top: 20px;">
			<c:if test="${requestScope.pageNo != 1}">
				<a href="BookManagerServlet?method=getBookPage&pageNo=1">首页</a>
				<a href="BookManagerServlet?method=getBookPage&pageNo=${requestScope.pageNo-1}">上一页</a>
			</c:if>
			<c:choose>
				<c:when test="${requestScope.totalPage < 5}">
					<c:set var="begin" value="1"></c:set>
					<c:set var="end" value="${requestScope.totalPage}"></c:set>
				</c:when>
				<c:when test="${requestScope.pageNo <= 2}">
					<c:set var="begin" value="1"></c:set>
					<c:set var="end" value="5"></c:set>
				</c:when>
				<c:otherwise>
					<c:set var="begin" value="${requestScope.pageNo-2}"></c:set>
					<c:set var="end" value="${requestScope.pageNo+2}"></c:set>
					<c:if test="${pageScope.end > requestScope.totalPage}">
						<c:set var="begin" value="${requestScope.totalPage-4}"></c:set>
						<c:set var="end" value="${requestScope.totalPage}"></c:set>
					</c:if>
				</c:otherwise>
			</c:choose>
			<c:forEach begin="${pageScope.begin}" end="${pageScope.end}" var="i">
				<c:if test="${requestScope.pageNo == pageScope.i}">
					<a href="BookManagerServlet?method=getBookPage&pageNo=${pageScope.i}" style="color: red;">[${pageScope.i}]</a>
				</c:if>
				<c:if test="${requestScope.pageNo != pageScope.i}">
					<a href="BookManagerServlet?method=getBookPage&pageNo=${pageScope.i}">${pageScope.i}</a>
				</c:if>
			</c:forEach>
			<c:if test="${requestScope.pageNo != requestScope.totalPage}">
				<a href="BookManagerServlet?method=getBookPage&pageNo=${requestScope.pageNo+1}">下一页</a>
				<a href="BookManagerServlet?method=getBookPage&pageNo=${requestScope.totalPage}">末页</a>
			</c:if>
			共${requestScope.totalPage}页，${requestScope.count}条记录 到第<input value="${requestScope.pageNo}" id="pn_input"/>页
			<input type="button" value="确定" id="btnId">
		</div>
	</div>
	
	<div id="bottom">
		<span>
			尚硅谷书城.Copyright &copy;2015
		</span>
	</div>
</body>
</html>